<template>
  <div>
  </div>
</template>

<script>
export default {
  model: {
    prop: 'modelVal',
    event: 'change'
  },
  props: {
    modelVal: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      val: {
        formId: '',
        formName: '',
        viewId: '',
        viewName: ''
      }
    }
  },
  mounted () {
    this.val = this.init(this.modelVal)
  },
  watch: {
    modelVal (v) {
      this.val = this.init(v)
    },
    val (v) {
      this.$emit('change', JSON.stringify(v))
    }
  },
  methods: {
    init (v) {
      try {
        this.val = JSON.parse(v)
      } catch (e) {
        this.val = {
          formId: '',
          formName: '',
          viewId: '',
          viewName: ''
        }
      }
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
